//
//  KDateFormatter.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/1.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "KDateFormatter.h"

@implementation KDateFormatter

+(NSDateFormatter *)shareManager{
    static NSDateFormatter *instance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        instance = [[NSDateFormatter alloc] init];
    });
    return instance;
}

+ (NSString *) dateToStringDate:(NSDate *)date formatString:(NSString *)formatString {
    NSDateFormatter *dateFormatter = [KDateFormatter shareManager];
    [NSTimeZone resetSystemTimeZone];
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
    [dateFormatter setDateFormat:formatString];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    return [dateFormatter stringFromDate:date];
}

+ (NSDate *)stringToDateString:(NSString *)dateString formatString:(NSString *)formatString {
    NSDateFormatter *dateFormatter = [KDateFormatter shareManager];
    [NSTimeZone resetSystemTimeZone];
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
    [dateFormatter setDateFormat:formatString];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    return [dateFormatter dateFromString:dateString];
}

@end
